package com.example.baselibrary.utils

import android.os.CountDownTimer

object TimeUtils {
    private var timer: CountDownTimer? = null

    /**
     * 倒计时
     */
    fun startTime(millisInFuture: Long, onClickTime: OnClickTime?) {
        timer?.cancel()
        timer =null
        timer = object : CountDownTimer(millisInFuture, 1000) {
            override fun onTick(millisUntilFinished: Long) {
                onClickTime?.cuuTime(millisUntilFinished)
            }

            override fun onFinish() {
                onClickTime?.onFinish()
            }
        }
        timer?.start()
    }

    interface OnClickTime {
        fun cuuTime(millisUntilFinished: Long)
        fun onFinish()
    }

    /**
     * 干掉倒计时
     */
    fun onDestroyTime() {
        timer?.cancel()
        timer = null
    }

}